package com.rchat.pocmini.activity.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.baoyz.swipemenulistview.SwipeMenuListView;

/**
 * Created by 59450 on 2017/4/21.
 */

public class CustomSwipeMenuListView extends SwipeMenuListView {


    public CustomSwipeMenuListView(Context context) {
        super(context);
    }

    public CustomSwipeMenuListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomSwipeMenuListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private boolean isSmooth = false;


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(isSmooth) {
            isSmooth = false;
            return true;
        }
        return false;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        float mDownX = 0;
        float mDownY = 0;
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN :
                mDownX = ev.getX();
                mDownY = ev.getY();
                getParent().requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_MOVE :
                if(Math.abs(ev.getX() - mDownX)<Math.abs(ev.getY() - mDownY)){
                    isSmooth = true;
                    return false;
//                    getParent().requestDisallowInterceptTouchEvent(true);
                }else {
                    return true;
//                    getParent().requestDisallowInterceptTouchEvent(false);
                }
            case MotionEvent.ACTION_UP :
            case MotionEvent.ACTION_CANCEL:
                getParent().requestDisallowInterceptTouchEvent(false);
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

}
